home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9310.ZIP / DFPP03.ZIP / SCREEN.CPP < prev    next >
C/C++ Source or Header  |  1993-09-24  |  4KB  |  151 lines

  1. // ----------- screen.cpp
  2.  
  3. #include <string.h>
  4. #include "desktop.h"
  5.  
  6. Screen::Screen()
  7. {
  8.     if (isEGA() || isVGA())    {
  9.         // --- turn blinking off
  10.         regs.x.ax = 0x1003;
  11.         regs.h.bl = 0;
  12.         int86(VIDEO, ®s, ®s);
  13.     }
  14.     // ---- get the video mode and page
  15.     regs.h.ah = 15;
  16.     int86(VIDEO, ®s, ®s);
  17.     mode = regs.h.al;
  18.     page = regs.x.bx;
  19.     page &= 0xff00;
  20.     mode &= 0x7f;
  21.     // ---- Monochrome Display Adaptor or text mode
  22.     if (isMono())
  23.         address = 0xb000;
  24.     else
  25.         // ------ Text mode
  26.         address = 0xb800 + page;
  27.     width = *(unsigned char far *)( MK_FP(0x40,0x4a) );
  28.     if (isVGA() || isEGA())
  29.         height = *(unsigned char far *)( MK_FP(0x40,0x84) )+1;
  30.     else
  31.         height = 25;
  32. }
  33.  
  34. // ---- test for EGA
  35. Bool Screen::isEGA(void)
  36. {
  37.     if (isVGA())
  38.         return False;
  39.     regs.h.ah = 0x12;
  40.     regs.h.bl = 0x10;
  41.     int86(VIDEO, ®s, ®s);
  42.     return (Bool) (regs.h.bl != 0x10);
  43. }
  44.  
  45. // ---- test for VGA
  46. Bool Screen::isVGA(void)
  47. {
  48.     regs.x.ax = 0x1a00;
  49.     int86(VIDEO, ®s, ®s);
  50.     return (Bool) (regs.h.al == 0x1a && regs.h.bl > 6);
  51. }
  52.  
  53. // --------- scroll the screen d: 1 = up, 0 = dn
  54. void Screen::Scroll(Rect &rc, int d, int fg, int bg)
  55. {
  56.     desktop.mouse().Hide();
  57.     regs.h.cl = rc.Left();
  58.     regs.h.ch = rc.Top();
  59.     regs.h.dl = rc.Right();
  60.     regs.h.dh = rc.Bottom();
  61.     regs.h.bh = clr(fg,bg);
  62.     regs.h.ah = 7 - d;
  63.     regs.h.al = 1;
  64.     int86(VIDEO, ®s, ®s);
  65.     desktop.mouse().Show();
  66. }
  67.  
  68. // -------- read a character of video memory
  69. unsigned int Screen::GetVideoChar(int x, int y)
  70. {
  71.     int c;
  72.     desktop.mouse().Hide();
  73.     int far *fp = (int far *) MK_FP(address, vad(x,y));
  74.     c = *fp;
  75. //    c = peek(address, vad(x,y));
  76.     desktop.mouse().Show();
  77.     return c & 255;
  78. }
  79.  
  80. // -------- write a character of video memory
  81. void Screen::PutVideoChar(int x, int y, unsigned int c)
  82. {
  83.     if (x >= 0 && x < width && y >= 0 && y < height)    {
  84.         desktop.mouse().Hide();
  85.         int far *fp = (int far *) MK_FP(address, vad(x,y));
  86.         *fp = c;
  87. //        poke(address, vad(x,y), c);
  88.         desktop.mouse().Show();
  89.     }
  90. }
  91.  
  92. // --------- Write a string to video memory
  93. void Screen::WriteVideoString(const char *s,int x,int y,int fg,int bg)
  94. {
  95.     if (x >= 0 && x < width && y >= 0 && y < height)    {
  96.         int len = strlen(s);
  97.         int *ln = new int[len];
  98.         int *cp1 = ln;
  99.         int col = clr(fg,bg) << 8;
  100.         while (*s)    {
  101.             *cp1++ = (*s & 255) | col;
  102.             s++;
  103.         }
  104.         if (x + len >= width)
  105.             len = width - x;
  106.         desktop.mouse().Hide();
  107.         movedata(FP_SEG(ln),FP_OFF(ln),address,vad(x,y),len*2);
  108.         desktop.mouse().Show();
  109.         delete [] ln;
  110.     }
  111. }
  112.  
  113. // -- read a rectangle of video memory into a save buffer
  114. void Screen::GetBuffer(Rect &rc, char *bf)
  115. {
  116.     if (rc.Left() >= width || rc.Top() >= height)
  117.         return;
  118.     int ht = rc.Bottom()-rc.Top()+1;
  119.     int bytes_row = (rc.Right()-rc.Left()+1) * 2;
  120.     unsigned vadr = vad(rc.Left(), rc.Top());
  121.     desktop.mouse().Hide();
  122.     while (ht--)    {
  123.         movedata(address, vadr, FP_SEG(bf),
  124.                 FP_OFF(bf), bytes_row);
  125.         vadr += width*2;
  126.         bf = (char far *)bf + bytes_row;
  127.     }
  128.     desktop.mouse().Show();
  129. }
  130.  
  131. // -- write a rectangle of video memory from a save buffer
  132. void Screen::PutBuffer(Rect &rc, char *bf)
  133. {
  134.     if (rc.Left() >= width || rc.Top() >= height)
  135.         return;
  136.     int ht = rc.Bottom()-rc.Top()+1;
  137.     int bytes_row = (rc.Right()-rc.Left()+1) * 2;
  138.     unsigned vadr = vad(rc.Left(), rc.Top());
  139.     desktop.mouse().Hide();
  140.     while (ht--)    {
  141.         movedata(FP_SEG(bf), FP_OFF(bf), address,
  142.                 vadr, bytes_row);
  143.         vadr += width*2;
  144.         bf += bytes_row;
  145.     }
  146.     desktop.mouse().Show();
  147. }
  148.  
  149.  
  150.  
  151.